From 56bec0c70c1c507934a27b6c241b63360f53e731 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 4 Jun 2013 10:41:44 +0200 Subject: [PATCH] gdkwindow: Respect cairo surfaces with device scale If a cairo_surface for a window has a device scale set we need to respect this when creating a similar window. I.e. we want to then automatically create a larger window which inherits the scale from the original. We also need to calculate a different device_offset if there is a device_scale set. --- gdk/gdkwindow.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c index 99fed9b4fe..6943388e04 100644 --- a/gdk/gdkwindow.c +++ b/gdk/gdkwindow.c @@ -2757,6 +2757,7 @@ gdk_window_begin_paint_region (GdkWindow *window, GdkWindowImplClass *impl_class; GdkWindowPaint *paint; GSList *list; + double sx, sy; gboolean needs_surface; g_return_if_fail (GDK_IS_WINDOW (window)); @@ -2783,7 +2784,11 @@ gdk_window_begin_paint_region (GdkWindow *window, gdk_window_get_content (window), MAX (clip_box.width, 1), MAX (clip_box.height, 1)); - cairo_surface_set_device_offset (paint->surface, -clip_box.x, -clip_box.y); + sx = sy = 1; +#ifdef HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE + cairo_surface_get_device_scale (paint->surface, &sx, &sy); +#endif + cairo_surface_set_device_offset (paint->surface, -clip_box.x*sx, -clip_box.y*sy); } for (list = window->paint_stack; list != NULL; list = list->next) @@ -9198,10 +9203,18 @@ gdk_window_create_similar_surface (GdkWindow * window, int height) { cairo_surface_t *window_surface, *surface; + double sx, sy; g_return_val_if_fail (GDK_IS_WINDOW (window), NULL); - + window_surface = gdk_window_ref_impl_surface (window); + sx = sy = 1; +#ifdef HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE + cairo_surface_get_device_scale (window_surface, &sx, &sy); +#endif + + width = width * sx; + height = height * sy; switch (_gdk_rendering_mode) { @@ -9224,6 +9237,10 @@ gdk_window_create_similar_surface (GdkWindow * window, break; } +#ifdef HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE + cairo_surface_set_device_scale (surface, sx, sy); +#endif + cairo_surface_destroy (window_surface); return surface; -- 2.30.2